package app.fugema.shop.main.order.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.base.common.app.LoginUtils;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.OnClickCheckedUtil;
import com.base.common.utils.UIUtils;
import com.base.common.view.base.BaseTitleActivity;
import com.base.common.viewmodel.BaseViewObserver;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ActivityShoppingDeliveryCheckDetailBinding;
import app.fugema.shop.main.order.adapter.ShoppingDeliveryCheckDetailAdapter;
import app.fugema.shop.main.order.model.OrderExpressResult;
import app.fugema.shop.main.order.vm.OrderListVM;

public class DeliveryCheckDetailActivity extends BaseTitleActivity<ActivityShoppingDeliveryCheckDetailBinding, OrderListVM>
{
    //物流信息页面
    public static void start(Context context, String orderNumber)
    {
        Intent starter = new Intent(context, DeliveryCheckDetailActivity.class);
        starter.putExtra("orderNumber", orderNumber);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopping_delivery_check_detail);
    }

    private String userkey = "";
    private OrderExpressResult expressResult;
    @Override
    protected int getStatusBarColor()
    {
        return R.color.redColor;
    }

    @Override
    protected void initView()
    {
        super.initView();
        setCloseImg(R.mipmap.ic_back_white);
        setTitle("订单跟踪",R.color.white);
        checkDetailAdapter = new ShoppingDeliveryCheckDetailAdapter();
        binding.rvRecyclerView.setAdapter(checkDetailAdapter);

        binding.btnCopy.setOnClickListener(new OnClickCheckedUtil() {
            @Override
            public void onClicked(View view) {
                if( UIUtils.isNotEmpty( expressResult ) )
                {
                    UIUtils.copy( DeliveryCheckDetailActivity.this ,expressResult.getExpressNum() );
                    UIUtils.showToastSafes("已复制物流单号");
                }
            }
        });


    }

    private String orderNumber;
    private ShoppingDeliveryCheckDetailAdapter checkDetailAdapter;

    @Override
    protected void initData(Intent intent)
    {
        super.initData(intent);
        orderNumber = intent.getStringExtra("orderNumber");
        userkey = LoginUtils.getToken();
        viewModel.checkOrderExpressInfo(Long.parseLong( orderNumber ) , userkey)
                 .observe(this, new BaseViewObserver<LiveDataWrapper<OrderExpressResult>>(getActivity())
                 {
                        @Override
                        protected void onSuccess(LiveDataWrapper<OrderExpressResult> data)
                        {
                            //{"success":true, "ExpressNum":"12124312132","ExpressCompanyName":"申通快递", "Comment":{"success":false,"msg":"暂无物流信息","data":[]}}

                            if( data.data.isSuccess() )
                            {
                                expressResult = data.data;
                                binding.setItem( data.data );
                                binding.executePendingBindings();

                            }

                            /*
                            binding.setItem(data.data.getData());
                            List<ADInfo> list = new ArrayList<>();
                            for (OrderExpressResult.DataBean datum : data.data.getData().getData()) {
                                ADInfo adInfo = new ADInfo();
                                adInfo.setImageName(DateUtils.dateStringToString(datum.getTime(), "MM-dd\nHH:mm"));
                                adInfo.setImageContent("【" + datum.getLocation() + "】" + datum.getContext());
                                list.add(adInfo);
                            }
                            */
                            //checkDetailAdapter.setDataList(list);
                        }

                        @Override
                        public boolean isEmptyData(LiveDataWrapper<OrderExpressResult> data)
                        {
                            return UIUtils.isEmpty(data.data);
                        }
                 });
    }
}
